package basketball_behaviour

import (
	"longmen/server/config/global"
	"longmen/server/internal/services/nami/services/sports/basketball"
	"longmen/server/pkg/db/mysql/models/models_sports"
)

type (
	RecentApiResponse struct {
		Code  int `json:"code"`
		Query struct {
			Total int    `json:"total"`
			Type  string `json:"type"`
			ID    int    `json:"id"`
			MinID int    `json:"min_id"`
			MaxID int    `json:"max_id"`
			Limit int    `json:"limit"`
		} `json:"query"`
		Results []Result `json:"results"`
	}
	Result struct {
		ID            int    `json:"id"`
		CompetitionID int    `json:"competition_id"`
		HomeTeamID    int    `json:"home_team_id"`
		AwayTeamID    int    `json:"away_team_id"`
		Kind          int    `json:"kind"`
		PeriodCount   int    `json:"period_count"`
		StatusID      int    `json:"status_id"`
		MatchTime     int64  `json:"match_time"`
		Neutral       int    `json:"neutral"`
		HomeScores    Scores `json:"home_scores"`
		AwayScores    Scores `json:"away_scores"`
		HomePosition  string `json:"home_position"`
		AwayPosition  string `json:"away_position"`
		Coverage      struct {
			Mlive        int `json:"mlive"`
			Intelligence int `json:"intelligence"`
		} `json:"coverage"`
		VenueID  int `json:"venue_id"`
		SeasonID int `json:"season_id"`
		Round    struct {
			StageID  int `json:"stage_id"`
			GroupNum int `json:"group_num"`
			RoundNum int `json:"round_num"`
		} `json:"round"`
		UpdatedAt      int        `json:"updated_at"`
		OverTimeScores OverScores `json:"over_time_scores"` // 加时赛比分
	}
)

func (r RecentApiResponse) UpdateMatchInterFaces() []basketball.UpdateMatchInterface {
	a := make([]basketball.UpdateMatchInterface, 0)
	for _, record := range r.Results {
		a = append(a, record)
	}
	global.Log.Info("count : ", len(r.Results))
	return a
}

func (r Result) GetUpdate() models_sports.BasketballMatch {
	return models_sports.BasketballMatch{
		ID:             r.ID,
		CompetitionID:  r.CompetitionID,
		HomeTeamID:     r.HomeTeamID,
		AwayTeamID:     r.AwayTeamID,
		Kind:           r.Kind,
		PeriodCount:    r.PeriodCount,
		StatusID:       models_sports.BasketBallMatchStatus(r.StatusID),
		MatchTime:      r.MatchTime,
		Neutral:        r.Neutral,
		HomeScores:     r.HomeScores.String(),
		AwayScores:     r.AwayScores.String(),
		OverTimeScores: r.OverTimeScores.String(),
		HomePosition:   r.HomePosition,
		AwayPosition:   r.AwayPosition,
		Mlive:          r.Coverage.Mlive,
		Intelligence:   r.Coverage.Intelligence,
		VenueID:        r.VenueID,
		SeasonID:       r.SeasonID,
		StageID:        r.Round.StageID,
		GroupNum:       r.Round.GroupNum,
		RoundNum:       r.Round.RoundNum,
		UpdatedAt:      r.UpdatedAt,
	}
}
